
const sm2 = require('sm-crypto').sm2
// 获取密钥对
// let keypair = sm2.generateKeyPairHex()
// const publicKey = keypair.publicKey // 公钥
// const privateKey = keypair.privateKey // 私钥

// 和后端约定得密钥对公钥  如公钥字符串前面无04需加上04
const publicKey =`04283cb64d393ea298024d9c1905cd022eabb753dc52a0c0934f43a241fa89821cf4bd0d1aeb596851394a4bcfa6625665e9b5f83c94bc54a29816a53fda2a2602`
const privateKey = `2583428ed909d6b43ddc14122e486de28ed57ed8bf9f124661fe949aa72e2f34` // 私钥
// console.log('publicKey',publicKey);
// console.log('privateKey',privateKey);
let verifyResult = sm2.verifyPublicKey(publicKey)
// console.log('verifyResult',verifyResult);
// sm2 加密
export const doEncrypt = function (data) {
  const cipherMode = 1
  const result = sm2.doEncrypt(data, publicKey, cipherMode)
  return result
}

// sm-  解密
export const doDecrypt = function (data) {
  const cipherMode = 1
  const result = sm2.doDecrypt(data, privateKey, cipherMode)
  return result
}

export default {
	doEncrypt,
	doDecrypt
}
